﻿using Styx;
using Styx.Common;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Media;


using HKM = Paster.Managers.HotkeyManagers;
using P = Paster.GUI.CommonSettings;


namespace Paster.Managers
{
    class HotkeyManagers
    {
        public static LocalPlayer Me { get { return StyxWoW.Me; } }

        public static bool keysRegistered { get; set; }
        public static bool movementDisable { get; set; }
        public static bool facingDisable { get; set; }

        public static string[] disableMovement
        {
            get
            {
                string m = P.myPrefs.KeyDisableMovement.ToString();
                string[] mm = m.Split(',');
                return mm;
            }
        }
        public static string[] disableFacing
        {
            get
            {
                string m = P.myPrefs.KeyDisableFacing.ToString();
                string[] mm = m.Split(',');
                return mm;
            }
        }

        private static Keys keyMovementDisable { get { return P.myPrefs.KeyDisableMovement == Keys.None ? (Keys)Enum.Parse(typeof(Keys), "M") : (Keys)Enum.Parse(typeof(Keys), disableMovement[0]); } }
        private static Keys keyFacingDisable { get { return P.myPrefs.KeyDisableFacing == Keys.None ? (Keys)Enum.Parse(typeof(Keys), "F") : (Keys)Enum.Parse(typeof(Keys), disableFacing[0]); } }

        private static ModifierKeys modifKeyMovementDisable { get { return P.myPrefs.KeyDisableMovement == Keys.None ? (ModifierKeys)Enum.Parse(typeof(ModifierKeys), "Alt") : (ModifierKeys)Enum.Parse(typeof(ModifierKeys), disableMovement[1]); } }
        private static ModifierKeys modifKeyFacingDisable { get { return P.myPrefs.KeyDisableFacing == Keys.None ? (ModifierKeys)Enum.Parse(typeof(ModifierKeys), "Alt") : (ModifierKeys)Enum.Parse(typeof(ModifierKeys), disableFacing[1]); } }

        public static void registerHotKeys()
        {
            if (keysRegistered)
                return;

            HotkeysManager.Register("movementDisable", keyMovementDisable, modifKeyMovementDisable, ret =>
                {
                    movementDisable = !movementDisable;
                    Lua.DoString(movementDisable ? @"print('Movement: \124cFF15E61C Disabled!')" : @"print('Movement: \124cFFE61515 Enabled!')");

                    string msgStop = "Movement Disabled !, press " + modifKeyMovementDisable + " + " + keyMovementDisable + " again to enable Movement";
                    string msgOn = "Movement Enabled !, press " + modifKeyMovementDisable + " + " + keyMovementDisable + " again to disable Movement";

                    if (P.myPrefs.PrintRaidstyleMsg)
                        Lua.DoString(
                            movementDisable ?
                            "RaidNotice_AddMessage(RaidWarningFrame, \"" + msgStop + "\", ChatTypeInfo[\"RAID_WARNING\"]);"
                            :
                            "RaidNotice_AddMessage(RaidWarningFrame, \"" + msgOn + "\", ChatTypeInfo[\"RAID_WARNING\"]);");
                });

            HotkeysManager.Register("facingDisable", keyFacingDisable, modifKeyFacingDisable, ret =>
            {
                facingDisable = !facingDisable;
                Lua.DoString(facingDisable ? @"print('facing: \124cFF15E61C Disabled!')" : @"print('facing: \124cFFE61515 Enabled!')");

                string msgStop = "facing Disabled !, press " + modifKeyFacingDisable + " + " + keyFacingDisable + " again to enable facing";
                string msgOn = "facing Enabled !, press " + modifKeyFacingDisable + " + " + keyFacingDisable + " again to disable facing";

                if (P.myPrefs.PrintRaidstyleMsg)
                    Lua.DoString(
                        facingDisable ?
                        "RaidNotice_AddMessage(RaidWarningFrame, \"" + msgStop + "\", ChatTypeInfo[\"RAID_WARNING\"]);"
                        :
                        "RaidNotice_AddMessage(RaidWarningFrame, \"" + msgOn + "\", ChatTypeInfo[\"RAID_WARNING\"]);");
            });





            keysRegistered = true;
            Logging.Write(" " + "\r\n");

            Lua.DoString(@"print('Hotkeys: \124cFF15E61C Registered!')" + "\r\n");
            Logging.Write(Colors.Bisque, "Movement Key: " + modifKeyMovementDisable + "+ " + keyMovementDisable);
            Logging.Write(Colors.Bisque, "Facing Key:  " + modifKeyFacingDisable + "+ " + keyFacingDisable);
        }


        public static void removeHotkeys()
        {
            if (!keysRegistered)
                return;

            HotkeysManager.Unregister("movementDisable");
            HotkeysManager.Unregister("facingDisable");

            movementDisable = false;
            facingDisable = false;
            keysRegistered = false;

            Lua.DoString(@"print('Hotkeys: \124cFFE61515 Removed!')");
            Logging.Write(Colors.OrangeRed, "Hotkeys: Removed!");
        }

    }
}
